<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of User
 *
 * @author Pablo Barrenechea
 */
class MD_ProductCategory
{
	public static function getEnabledCategories()
	{
		return TN_Db::getInstance()->fetchAll("SELECT * FROM product_category  where enabled = 1 ORDER BY name");
	}
	
    public static function getAll()
    {
    
        return TN_Db::getInstance()->fetchAll("SELECT * FROM product_category ORDER BY id");
    }
    
    public static function getName($id)
    {
    	$category = TN_Db::getInstance()->fetchAll("select name from product_category where id = '$id'");
    	return $category[0]['name'];
    }
    
    public static function getCategoryById($id)
    {
    	$category = TN_Db::getInstance()->fetchAll("select * from product_category where id = '$id'");
    	return $category[0];
    }
    
    public static function add($name, $image, $description,$enabled)
    {
    	TN_Db::getInstance()->insert('product_category', array('name'=> $name, 'image' => $image, 'description' => $description, 'enabled' => $enabled));
    }
    
    public static function update($id,$name, $image, $description, $enabled)
    {
    	TN_Db::getInstance()->update('product_category', array( 'name'=> $name, 'image' => $image, 'description' => $description , 'enabled' => $enabled) , "id = '$id' ");
    }
    
    public static function delete($id)
    {
    	TN_Db::getInstance()->delete('product_category', "id = '$id' "); 
    }
 	
    public static function lastId()
    {
    	return TN_Db::getInstance()->lastInsertId('product_category');
    }
    
    public static function setImage($id, $img)
    {
    	TN_Db::getInstance()->update('product_category', array('image' => $img), "id = '$id' ");
    }
}
?>